import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../services/app_theme_services.dart';
import 'me_auction_logic.dart';

class MeAuctionPage extends GetView<MeAuctionLogic> {
  final logic = Get.put(MeAuctionLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          elevation: 0,
          automaticallyImplyLeading: true,
          iconTheme: const IconThemeData(color: Colors.black),
          centerTitle: true,
          title: Text("我的拍品", style: AppThemeServices.textTheme.appBarTitle),
        ),
        body: Container(
          color: const Color.fromRGBO(247, 248, 250, 1),
          child: GetBuilder<MeAuctionLogic>(
            assignId: true,
            builder: (logic) {
              return GridView.builder(
                padding: const EdgeInsets.all(10),
                gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 2,
                    mainAxisSpacing: 10,
                    crossAxisSpacing: 10,
                    childAspectRatio: 4 / 5),
                itemBuilder: (context, index) {
                  var map = logic.list[index];
                  return Container(
                    decoration: const BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(7.5))),
                    child: Column(
                      children: [
                        Expanded(
                            child: Container(
                                child: Stack(children: [
                          Container(),
                          Center(
                            child: Container(
                              padding: const EdgeInsets.only(top: 5),
                              child: Image.network(
                                map['image'],
                                errorBuilder: (_, e, r) => Container(),
                                fit: BoxFit.cover,
                              ),
                            ),
                          ),
                          Container(
                            decoration: const BoxDecoration(
                                color: Color.fromRGBO(0, 195, 179, 1),
                                borderRadius: BorderRadius.only(
                                    topLeft: Radius.circular(7.5))),
                            height: 22,
                            width: 46,
                            child: Center(
                              child: Text(
                                map['hashStatus'] == 1 ? '正常' : '拍卖中',
                                style: const TextStyle(
                                    fontWeight: FontWeight.w500,
                                    fontSize: 11,
                                    color: Colors.white),
                              ),
                            ),
                          ),
                        ]))),
                        Container(
                            padding: const EdgeInsets.all(8),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  map['name'],
                                  maxLines: 2,
                                  style: const TextStyle(
                                      fontSize: 14,
                                      overflow: TextOverflow.ellipsis,
                                      fontWeight: FontWeight.w500,
                                      color: Color.fromRGBO(50, 50, 51, 1)),
                                ),
                                const SizedBox(
                                  height: 5,
                                ),
                                Row(
                                  mainAxisAlignment:
                                      MainAxisAlignment.spaceBetween,
                                  children: [
                                    RichText(
                                        text: TextSpan(
                                            text: '¥',
                                            style: const TextStyle(
                                                fontSize: 12,
                                                fontWeight: FontWeight.w600,
                                                color: Color.fromRGBO(
                                                    255, 77, 77, 1)),
                                            children: [
                                          TextSpan(
                                              text: ((map['amount'] ?? 0.00) /
                                                      100)
                                                  .toStringAsFixed(2),
                                              style: const TextStyle(
                                                fontSize: 18,
                                                fontWeight: FontWeight.w600,
                                                color: Color.fromRGBO(
                                                    255, 77, 77, 1),
                                              )),
                                        ])),
                                    map['hashStatus'] == 1 ? GestureDetector(
                                      onTap: () {
                                        logic.shelves(map['id']);
                                      },
                                      child: Container(
                                        height: 25,
                                        width: 68,
                                        decoration: const BoxDecoration(
                                            borderRadius: BorderRadius.all(
                                                Radius.circular(45)),
                                            color:
                                                Color.fromRGBO(0, 195, 179, 1)),
                                        child: const Center(
                                          child: Text(
                                            '挂拍',
                                            style: TextStyle(
                                                fontWeight: FontWeight.w500,
                                                fontSize: 12,
                                                color: Colors.white),
                                          ),
                                        ),
                                      ),
                                    ) : Container(),
                                  ],
                                )
                              ],
                            ))
                      ],
                    ),
                  );
                },
                itemCount: logic.list.length,
              );
            },
          ),
        ));
  }
}
